# schemas.py
# Pydantic数据模型定义
from pydantic import BaseModel, EmailStr, Field
from typing import Optional, List
import datetime

class UserBase(BaseModel):
    username: str
    email: EmailStr
    nickname: Optional[str] = ""
    avatar: Optional[str] = ""
    contact: Optional[str] = ""
    is_seller: Optional[bool] = False

class UserCreate(UserBase):
    password: str

class UserOut(UserBase):
    id: int
    class Config:
        orm_mode = True

class CardBase(BaseModel):
    code: str
    name: str
    rarity: Optional[str] = ""
    type: Optional[str] = ""
    description: Optional[str] = ""

class CardCreate(CardBase):
    pass

class CardOut(CardBase):
    id: int
    class Config:
        orm_mode = True

class UserCardOut(BaseModel):
    id: int
    owner_id: int
    card: CardOut
    quantity: int
    price: float
    class Config:
        orm_mode = True

class OrderBase(BaseModel):
    quantity: int
    total_price: float
    status: str

class OrderCreate(BaseModel):
    user_card_id: int
    quantity: int

class OrderOut(OrderBase):
    id: int
    buyer_id: int
    seller_id: int
    user_card_id: int
    created_at: datetime.datetime
    class Config:
        orm_mode = True

class CartItemOut(BaseModel):
    id: int
    user_id: int
    user_card_id: int
    quantity: int
    class Config:
        orm_mode = True 